<template>
	<div class="weui-panel" style="height: 100%;width: 100%; background-color:#efefef ;">
		<div class="weui-cell" style="padding: 0.5rem;border-bottom: #d8d8d8;">
			<input type="button" class="btn returnBtn" @click="goBack" value="返回"></input>
			<input type="button" class="btn" style="display: flex;margin-left: 65%;padding: 3px 8px;" value="新增"
				@click="showAdd"></input>
		</div>
		<div class="weui-panel__bd" style="background-color: white;height: 90%;overflow: auto;">
			<div class="weui-cells">
				<a @click="showAdd(item)" class="weui-media-box weui-media-box_appmsg" v-for="(item, index) in recharges">
					<div class="weui-media-box__hd">
						<img class="weui-media-box__thumb" src="../../assets/img/wx/recharge.png">
					</div>
					<div class="weui-media-box__bd" style="text-align: left;">
						<h4 class="weui-media-box__title">售价{{item.oldSale}}元</h4>
						<h4 class="weui-media-box__title">优惠价{{item.newSale}}元</h4>
					</div>
				</a>
			</div>
		</div>
		<!-- 弹框新增 -->
		<div v-if="showAddFlag" style="width: 100%;height: 100%;position: absolute;z-index: 2051;background: rgba(0, 0, 0, 0.3);top: 0;bottom: 0;left: 0;">
			<div class="dialog" >
				<a class="weui-cell">
					<div class="weui-cell__bd" style="text-align: left;">
						<span class="demo_badge_title ">售价</span>
					</div>
					<div class="weui-cell__ft">
						<input type="text" v-model="param.oldSale" />
					</div>
				</a>
				<a class="weui-cell">
					<div class="weui-cell__bd" style="text-align: left;">
						<span class="demo_badge_title ">充值优惠售价</span>
					</div>
					<div class="weui-cell__ft">
						<input type="text" v-model="param.newSale" />
					</div>
				</a>
				<a class="weui-cell" style="width: 100%;">
					<button @click="saveDis" class="weui-btn weui-btn_default" >确定</button>
					<button @click="showAddFlag =false" class="weui-btn weui-btn_default" style="margin-top: 0;" >取消</button>
				</a>
			</div>
		</div>
		
	</div>


</template>

<script>
	import{showMsg} from '@/apis/common/common.js'
	import apis from '@/utils/apis.js'
	import {
		getDisCounts,saveDis
	} from '@/apis/wx/recharge.js'
	import constant from '@/utils/constant'

	export default {
		data() {
			return {
				account: "",
				recharges: [],
				param:{
					oldSale:0,
					newSale:0,
					flag:'tech',
				},
				showAddFlag:false,
			}
		},
		created() {
			debugger
			this.getDisCounts();
		},
		methods: {
			showAdd(item){
				if(item !=null && item !=undefined){
					this.param = item;
				}
				this.showAddFlag = true
			},
			//获取所有优惠充值信息
			getDisCounts() {
				this.recharges = [];
				getDisCounts(apis.getDisCounts + "?flag=tech&account=" + this.account).then(res => {
					if (res.resultCode == constant.SUCCESS && res.data) {
						this.recharges = res.data;
					}
				})
			},
			goBack(){
				this.$router.go(-1);
			},
			saveDis(){
				this.$showLoading({
					showLoadingToastFlag: true,
				});
				this.showAddFlag = false;
				saveDis(apis.saveDis,this.param).then(res=>{
					if (res.resultCode == constant.SUCCESS) {
						showMsg(this,res.resultMsg,null, "success")
					} else {
						showMsg(this,res.resultMsg,null, "danger")
					}
					this.$hideLoading();
					this.getDisCounts();
				}).catch(err =>{
					this.$hideLoading();
				})
			},	
		}
	}
</script>

<style scoped>
	@import "../../assets/css/returnBtn.css";
	.dialog{
		    width: 100%;
		    height: 40%;
		    position: absolute;
		    background-color: white;
		    margin-top: 30%;
			font-size: 1rem;
	}	
</style>
